<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="static/css/main.css" />
</head>
<body>
<div id="username-page">
    <div class="username-page-container">
        <h1 class="title">登录</h1>
        <form class="layui-form"  name="usernameForm" method="post" action="">
            <div class="form-group">
                <input type="text" name="name" placeholder="用户名" autocomplete="off" class="form-control" />
            </div>
            <div class="form-group">
                <input type="password" name="password" placeholder="密码" autocomplete="off" class="form-control" />
            </div>
            <div class="form-group">
                <button type="submit" class="accent username-submit" lay-submit lay-filter="formDemo">登 录</button>
            </div>
        </form>
    </div>
</div>
<script src="static/js/layui/layui.js"></script>
<script>
    layui.use(['form', 'jquery', 'layer'], function(){
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;

        form.on('submit(formDemo)', function(data){
            $.post("/login", data.field, function (res) {
                if (0 == res.code) {
                    layer.msg(res.msg);
                    setTimeout(function () {
                        window.location.href = res.data;
                    }, 500);
                } else {
                    layer.msg(res.msg);
                    return false;
                }
            });
            return false;
        });
    })
</script>
</body>
</html>